﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using automobili_data;
using automobili_data.interfaces;
/// <summary>
/// Summary description for SessionUtils
/// </summary>
public class SessionUtils
{
    public SessionUtils()
    {
        //
        // TODO: Add constructor logic here
        //
    }

    public static bool isCurrentUserAnnonimous()
    {
        return (HttpContext.Current.Session["korisnik"] == null);
    }

    public static void storeUserInformation(User korisnik)
    {
        if (HttpContext.Current.Session["korisnik"] == null)
        {
            Privilegije privilegije = AutomobiliDataManager.instance.dohvatiPrivilegije(korisnik);
            HttpContext.Current.Session.Add("korisnik", korisnik);
            
            HttpContext.Current.Session.Add("privilegije", privilegije);
            //throw new Exception("User is already present in Session");
        }
    }

    public static void removeUserInformation()
    {
        HttpContext.Current.Session.Remove("korisnik");
        HttpContext.Current.Session.Remove("privilegije");
    }
    

    public static User getCurrentUser()
    {
        if (HttpContext.Current.Session != null)
            return (User)HttpContext.Current.Session["korisnik"];
        return null;
    }
    public static Privilegije getCurrentPrivileges()
    {
        if (HttpContext.Current.Session != null)
            return (Privilegije)HttpContext.Current.Session["privilegije"];
        return null;
    }
}
